package com.yl.nettylearning.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @author yangl
 */
public class FileChannelImg {
    public static void main(String[] args) throws Exception{
        //创建输入流
        FileInputStream fileInputStream = new FileInputStream("D:\\a.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\b.jpg");
        //获取各个流对应的fileChannel
        FileChannel fileInputChannel = fileInputStream.getChannel();
        FileChannel fileOutputChannel = fileOutputStream.getChannel();
        //使用transferFrom完成拷贝
        fileOutputChannel.transferFrom(fileInputChannel, 0 ,fileInputChannel.size());
        //关闭流
        fileInputChannel.close();
        fileOutputChannel.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
